
<template>
  <div class="index" v-if="showIndex">
    <el-form :inline="true" class="form">
  <el-form-item label="">
    <el-select v-model="form.projectCode" placeholder="活动名称">
      <el-option label="全部" value=""></el-option>
      <el-option label="反三科" value="GroupBuy01SP"></el-option>
      <el-option label="线上加课" value="GroupBuy02SP"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="">
    <el-select v-model="form.payStatus" placeholder="支付状态">
      <el-option label="全部" value=""></el-option>
      <el-option label="初始化" value="0"></el-option>
      <el-option label="支付成功" value="1"></el-option>
      <el-option label="支付失败" value="2"></el-option>
      <el-option label="取消" value="3"></el-option>
    </el-select>
  </el-form-item>
      <el-form-item label="">
        <el-input v-model="form.text" placeholder="请输入订单编号/手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="exportOrders">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData.list" border style="width: 100%">
      <el-table-column fixed label="活动名称" width="150">
        <template scope="scope">
          {{scope.row.projectCode==='GroupBuy01SP'?'反三科':scope.row.projectCode==='GroupBuy02SP'?'线上加课':''}}
        </template>
      </el-table-column>
      <el-table-column fixed prop="orderId" label="订单编号" width="150">
      </el-table-column>
      <el-table-column prop="groupTypeStr" label="类型" width="120">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="120">
      </el-table-column>
      <el-table-column label="团长/团员" width="120">
        <template scope="scope">
          {{scope.row.type==='0'?'团长':'团员'}}
        </template>
      </el-table-column>
      <el-table-column prop="phone" label="手机号">
      </el-table-column>
      <el-table-column prop="goodsName" label="科目" width="120">
      </el-table-column>
      <el-table-column prop="channel" label="渠道" width="120">
      </el-table-column>
      <el-table-column prop="openId" label="openId" width="120">
      </el-table-column>
      <el-table-column prop="wxName" label="微信名称" width="120">
      </el-table-column>
      <el-table-column label="订单价格" width="120">
        <template scope="scope">
          {{scope.row.amount/100}}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="下单时间" width="120">
        <template scope="scope">
          {{scope.row.createTime | formatTime}}
        </template>
      </el-table-column>
      <el-table-column label="是否已通知" width="120">
        <template scope="scope">
          {{scope.row.isNotice===0?'初始化':scope.row.isNotice===1?'待处理':scope.row.isNotice===2?'成功':scope.row.isNotice===3?'失败':''}}
        </template>
      </el-table-column>
      <el-table-column label="是否同步" width="120">
        <template scope="scope">
          {{scope.row.isSync===0?'初始化':scope.row.isSync===1?'待处理':scope.row.isSync===2?'同步成功':scope.row.isSync===3?'同步失败':''}}
        </template>
      </el-table-column>
      <el-table-column label="订单状态" width="120">
        <template scope="scope">
          {{scope.row.payStatus===0?'初始化':scope.row.payStatus===1?'支付成功':scope.row.payStatus===2?'支付失败':scope.row.payStatus===3?'取消':''}}
        </template>
      </el-table-column>
      <el-table-column label="成团状态" width="120">
        <template scope="scope">
          {{scope.row.status==='0'?'初始化':scope.row.status==='1'?'满标成功':scope.row.status==='2'?'差额成功':scope.row.status==='3'?'流失':''}}
        </template>
      </el-table-column>
      <el-table-column label="申请退款时间" width="120">
        <template scope="scope">
          {{scope.row.refundTime | formatTime}}
        </template>
      </el-table-column>
      <el-table-column label="退款处理状态" width="120">
        <template scope="scope">
          {{scope.row.refundStatus===0?'已发起':scope.row.refundStatus===1?'退款成功':scope.row.refundStatus===2?'退款失败':''}}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button @click="refund(scope.row)" type="text" size="small">发起退款</el-button>
          <el-button type="text" size="small" @click="asyncOrder(scope.row)">同步订单</el-button>
          <el-button type="text" size="small" @click="sycnSP(scope.row)">同步SP</el-button>
        </template>
      </el-table-column>
    </el-table>
    <v-pagination ref="pagin" class="pag" :total="tableData.total" @getListResult="getUser" :currentPage="form.pageIndex"></v-pagination>
  </div>
</template>

<script>
import VPagination from './Pagination'
import io from '../lib/io'
export default {
  name: 'index',
  components: {
    VPagination
  },
  data() {
    return {
      showIndex: false,
      tableData: [],
      form: {
        pageIndex: 1,
        pageSize: 10,
        text:'',
        payStatus:null,
        projectCode:null
      }
    }
  },
  created() {
    if(sessionStorage.getItem('pw')!=='yuyou123'){
    this.init()
    }else{
      this.showIndex=true
    }
    this.getUser()
  },
  methods: {
    exportOrders(){
      console.log(this.form)
      this.$confirm('此操作将导出当前订单, 是否继续?', '提示', {
        type: 'warning'
      }).then(async () => {
        window.open(io.exportOrders+'?text='+this.form.text+'&payStatus='+(this.form.payStatus||'')+'&projectCode='+this.form.projectCode)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    onSubmit(){
      this.$refs.pagin.changePage(1)
      this.getUser({pageIndex:1})
    },
    refund(row) {
      this.$confirm('此操作将发起该订单的退款, 是否继续?', '提示', {
        type: 'warning'
      }).then(async () => {
        let { data } = await io.post(io.refundByOrderId, { orderId: row.orderId,projectCode:row.projectCode })
        if (data.success) {
          this.$message({
            type: 'success',
            message: '发起退款成功!'
          });
          this.getUser()
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    sycnSP(row) {
      this.$confirm('此操作将同步白名单到shiping.com, 是否继续?', '提示', {
        type: 'warning'
      }).then(async () => {
        let { data } = await io.post(io.sycnSP, { orderId: row.orderId,projectCode:row.projectCode })
        if (data.success) {
          this.$message({
            type: 'success',
            message: '同步成功!'
          });
          this.getUser()
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    asyncOrder(row) {
      this.$confirm('此操作将同步该订单, 是否继续?', '提示', {
        type: 'warning'
      }).then(async () => {
        let { data } = await io.post(io.sycnByOrderId, { orderId: row.orderId,projectCode:row.projectCode })
        if (data.success) {
          this.$message({
            type: 'success',
            message: '同步成功!'
          });
          this.getUser()
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    async getUser(opt) {
      opt?this.form.pageIndex=opt.pageIndex:''
      let { data } = await io.post(io.getAllUserOrders, { ...this.form, ...opt })
      if (data.success) {
        this.tableData = data.data
      }
    },
    init() {
      this.$prompt('请输入密码', '提示', {
      }).then(({ value }) => {
        if (value === 'yuyou123') {
          this.showIndex = true
          sessionStorage.setItem('pw','yuyou123')
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    },
  },
}
</script>
<style scoped>
.form{
  text-align: left;
}
</style>


